home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 2.4 KB | 88 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // USubstitution.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __USUBSTITUTION__
- #include "USubstitution.h"
- #endif
-
- // MacApp
-
- #ifndef __UASSOCIATION__
- #include "UAssociation.h"
- #endif
-
- #ifndef __ULISTITERATOR__
- #include "UListIterator.h"
- #endif
-
- //----------------------------------------------------------------------------------------
-
- TAssociation* gParamTxt; // Used for text substitution
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUSubstitution:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUSubstitution()
- {
- if (!gParamTxt)
- {
- gParamTxt = new TAssociation;
- gParamTxt->IAssociation();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MAParamText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void MAParamText(const CStr255& keyStr,
- const CStr255& valueStr)
-
- {
- #if qDebug
- FailNonObject(gParamTxt);
- #endif
- gParamTxt->InsertEntry(keyStr, valueStr);
- }
-
- //----------------------------------------------------------------------------------------
- // MAReplaceText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void MAReplaceText(CStr255& theText)
- {
- #if qDebug
- FailNonObject(gParamTxt);
- #endif
- CArrayIterator iter(gParamTxt->fEntries);
-
- for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
- {
- TEntry* anEntry = (TEntry*)gParamTxt->fEntries->At(i);
- short index;
-
- while ((index = theText.Pos(**(anEntry->fKey))) != 0)
- {
- theText.Delete(index, (**(anEntry->fKey)).Length());
- if (theText.Length() + (**(anEntry->fValue)).Length() < sizeof(CStr255))
- theText.Insert(**(anEntry->fValue), index);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // End of USubstitution.cp
-
- #pragma segment Inline
-